Yes. (Because the string "34.56" can't be converted into
an int
).
Exception
Here are two of the rules about how try/catch blocks work:
- The first
catch{}
block to match the type ofException
thrown gets control.- The most specific
Exception
types should appear first in the structure, followed by the more generalException
types.To make full sense of these rules you need to know more about
Exception
types. Inspect the above hierarchy diagram ofException
.An
ArithmeticException
is thrown for some types of arithmetic problems, such as when a division by zero is attempted. (However, not all arithmetic problems cause anArithmeticException
.)In arranging the
try{}
blocks, a child class should appear before any of its ancestors. If class A is not an ancestor or descendant of class B, then it doesn't matter which appears first.
Should ArithmeticException
appear before
RunTimeException
in the list of catch
statements?